
import re




#1.提取Life和Python之间的字符串
string = "Life is simple,I use Python"

#方法1：使用组和search
#'()'作为一个组，group的参数为1取出第一个组
result1_1 = re.search('Life(.*)Python',string)
print("\n打印result1_1:")    
print(result1_1.group(1))     #打印： is simple,I use

#方法1：使用
#'()'作为一个组，group的参数为1取出第一个组
result1_2 = re.findall('Life(.*)Python',string)
print("\n打印result1_2:")         
print(result1_2)              #打印： [' is simple,I use ']



#1.提取Life和Python之间的字符串
string2 = "Life is simple,I use Python,I love Python"
result2 = re.search('Life(.*)Python(.*)Python',string2)
print("\n打印result2:")    
print(result2.group(0))     #打印：Life is simple,I use Python,I love Python
print(result2.group(1))     #打印：  is simple,I use
print(result2.group(2))     #打印：,I love
print(result2.groups())     #打印：(' is simple,I use ', ',I love ')
print(result2.group(0,1,2)) #打印：('Life is simple,I use Python,I love Python', ' is simple,I use ', ',I love ')
